package com.snow.useviewdemo.function.transition;

import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Pair;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback;
import com.snow.img.ImageUtil;
import com.snow.useviewdemo.Constants;
import com.snow.useviewdemo.R;
import com.snow.useviewdemo.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * author : snowzhao
 * e-mail : zyt@ttsing.com
 * date   : 2020/4/16
 * desc   :转场动画跳转
 */
public class TransitionRootTestActivity extends BaseActivity {

    @BindView(R.id.explode)
    Button explode;
    @BindView(R.id.slide)
    Button slide;
    @BindView(R.id.fade)
    Button fade;
    @BindView(R.id.sharedElements1)
    ImageView sharedElements1;
    @BindView(R.id.sharedElements2)
    Button sharedElements2;
    @BindView(R.id.sharedElements4)
    Button sharedElements4;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_transition_root_test;
    }

    @Override
    protected void setViewData(Bundle savedInstanceState) {
        ImageUtil.imageLoad(this, Constants.TEST_IMAGE, sharedElements1);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
            setExitSharedElementCallback(new MaterialContainerTransformSharedElementCallback());
            window.setSharedElementsUseOverlay(false);
        }
        super.onCreate(savedInstanceState);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @OnClick({R.id.explode, R.id.slide, R.id.fade, R.id.sharedElements1, R.id.sharedElements2, R.id.sharedElements4})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.explode://分解
                startActivity(new Intent(this, ExplodeActivity.class), ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
                break;
            case R.id.slide://滑动
                startActivity(new Intent(this, SlideActivity.class), ActivityOptions.makeSceneTransitionAnimation(this).toBundle());

                break;
            case R.id.fade://渐入渐出
                startActivity(new Intent(this, FadeActivity.class), ActivityOptions.makeSceneTransitionAnimation(this).toBundle());

                break;
            case R.id.sharedElements1://共享元素 下一个页面的按钮 相互绑定
                startActivity(new Intent(this, SharedElementsActivity.class),
                        ActivityOptions.makeSceneTransitionAnimation
                                (this, view, "myButton1")
                                .toBundle());
            case R.id.sharedElements2://共享元素 多个元素
                startActivity(new Intent(this, SharedElementsActivity.class),
                        ActivityOptions.makeSceneTransitionAnimation
                                (this,
                                        Pair.create(view, "myButton2"),
                                        Pair.create(view, "myButton3"))
                                .toBundle());
                break;
            case R.id.sharedElements4://共享元素 单独设置
                startActivity(new Intent(this, SharedElementsActivity.class),
                        ActivityOptions.makeSceneTransitionAnimation
                                (this, view, "myButton4")
                                .toBundle());
                break;
        }
    }
}
